package com.gitee.fdc.mongo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.mongodb.MongoClient;
import dev.morphia.Datastore;
import dev.morphia.Morphia;

@Configuration
public class DataSourceConfig {

    @Autowired
    private MongoProperties mongoProperties;

    @Bean
    public Morphia morphia() {
        final Morphia morphia = new Morphia();
//        morphia.mapPackageFromClass(Entities.class);
        return morphia;
    }

    @Bean
    public Datastore datastore(MongoClient mongoClient, Morphia morphia) {
        final Datastore datastore = morphia.createDatastore(mongoClient, mongoProperties.getDatabase());
        datastore.ensureIndexes();
        return datastore;
    }
}
